#include <iostream>

using namespace std;

typedef long long LL;

int main()
{
	int T;
	cin >> T;
	
	while (T -- )
	{
		LL l, r;
		cin >> l >> r;
		
		LL t = (l + r) % 9 * (r - l + 1) % 9 * 5 % 9 ;
		
		cout << t << endl;
	}
	
	return 0;
}